package com.woniuxy.controller;

import com.woniuxy.annotations.RequirePerm;
import com.woniuxy.entity.Product;
import com.woniuxy.entity.utils.ResponseEntity;
import com.woniuxy.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 马宇航
 * @Description: 商品服务的controller层
 * @DateTime: 22/10/10/0010 16:11
 * @Component: 成都蜗牛学苑
 **/
@RestController
@RefreshScope
public class ProductController {
    @Value("${server.port}")
    int port;
    @Value("${woniu.name}")
    String mayuhang;
    @Autowired
    ProductService productService;
    @GetMapping("/product/{id}")
    public ResponseEntity findById(@PathVariable Integer id) throws InterruptedException {
        ResponseEntity response = productService.findByPid(id);
        response.put("port",port);
        response.put("自定义参数",mayuhang);
        return response;
    }
    @PutMapping("/product")
    public ResponseEntity updateOne(@RequestBody Product product){
        return productService.updateOne(product);
    }
    /**
     * 根据价格搜索对应的商品
     * ChangeLog : 1. 创建 (22/10/11/0011 17:00 [马宇航]);
     * @param floorPrice 最低价格
     * @param ceilingPrice  最高价格
     * @return com.woniuxy.entity.utils.ResponseEntity
    */
    @GetMapping("/product")
    @RequirePerm("product::all")
    public ResponseEntity searchPrice(Double floorPrice,Double ceilingPrice){

        return productService.searchPrice(floorPrice,ceilingPrice);
    }

    /**
     * 根据书名或者价格或者id，搜索对应的商品
     * ChangeLog : 1. 创建 (22/10/11/0011 17:00 [马宇航]);
     * @return com.woniuxy.entity.utils.ResponseEntity
     */
    @GetMapping("/product/product")
    public ResponseEntity searchPrice(Integer pid,String name,Double price) throws InterruptedException {
        return productService.searchProduce(pid,name,price);
    }
}
